package hbr;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Test the movements of KillBot based of being fired on and wall hit.
 * 
 * @author Bryson Y. Hori
 */
public class TestMovement extends RobotTestBed {
  boolean movement = false;
  double xLast = 0;
  double yLast = 0;
  
  /**
   * Specifies that Corners and KillBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,hbr.KillBot";
  }
  
  /**
   * This test runs for 10 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if movement was made based of fire.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded (TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();
    
    if ((xLast == 0) && (yLast == 0)) {
      xLast = xPos;
      yLast = yPos;
    }
    else {
      if ((xLast != xPos) || (yLast != yPos)) {
        movement = true;
      }
      xLast = xPos;
      yLast = yPos;
    }
  }
  
  /**
   * After the battle, check to see that movement was made.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted (BattleCompletedEvent event) {
    assertTrue("Movement change", movement);
  }
}
